// Header.h: interface for the CSIPHeader class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_HEADER_H__316AE8D6_500A_4FE9_8398_4B2924A0B168__INCLUDED_)
#define AFX_HEADER_H__316AE8D6_500A_4FE9_8398_4B2924A0B168__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#pragma warning(disable:4786)
#pragma warning(disable:4530)
#include "public.h"
#include <stdlib.h>
#include "mystring.h"
#include <list>
#include "MethodTypes.h"

using namespace std;

#define SP		0x20
#define HTAB	0x09
#define CR		0x0D
#define LF		0x0A
#define COLON	':'
#define COMMA	','
#define SEMI	';'
#define SLASH	'/'
#define EQUAL	'='
#define LAQUOT	'<'
#define RAQUOT	'>'
#define STAR	'*'
#define DQUOTE	'\"'
#define LPAREN	'('
#define RPAREN	')'
#define MAX_METHOD_NAME_LEN 9

#define SKIPLWS(p,len,c,c1) 	c1 = SkipLWS(p,len - c);if(c1 == -1)return -1;p+=c1;c+=c1;

#define CLEARLIST(l,t) t *pt;while(l.empty() == false){pt = l.front();l.pop_front();delete pt;};
#define COPYLIST(s,d,t) list<t*>::const_iterator i;for(i=s.begin();i!=s.end();i++){d.push_back(new t(**i));}

void TrimLeft(char *s);
void TrimRight(char *s);
int SkipAllWhiteSpace(const char *s,int len);
int SkipLWS(const char *s,int len);

#ifdef IPV6_SUPPORT

bool is_ipv4_adddress(const char * p_address);
bool ishexdig(int ch);
bool is_ipv6_address(const char * p_address);
#endif


struct ParamPair{
	ParamPair(){m_pName = NULL;m_pValue = NULL;m_pNext = NULL;m_bHasQuote=false;};
	~ParamPair(){if(m_pName)delete[] m_pName;if(m_pValue)delete[]m_pValue;};
	char *m_pName;
	char *m_pValue;
	bool  m_bHasQuote;
	struct ParamPair *m_pNext;
};
class BASE_API CSIPHeaderParams{
public:
	
	CSIPHeaderParams(){m_pHead = m_pTail = m_pCur = NULL;m_nSize = 0;};
	virtual ~CSIPHeaderParams(){Clear();};
	void Clear();
	int ParseParams(const char *p,int len);
	int ParseURIParams(const char *p,int len);
	int ParseVIAParams(const char *p,int len);
	int ParseGenericParam(const char *pbuf,int len,mystring &v,bool &hasquote);
	mystring Encode();
	mystring EncodeHeaders();
	bool FindName(const char *pname)const;
	bool AddParam(const char *pname,const char *pvalue,bool hasquote=false);
	const char *GetValue(const char *pname)const;
//	bool FindParam(const char *pname)const;
	bool SetValue(const char *pname,const char *pvalue);
	const ParamPair* GetNext();
	const ParamPair* GetHeader()const {return m_pHead;};
	void SeekHead();
	int GetSize()const{return m_nSize;};
	CSIPHeaderParams& operator=(const CSIPHeaderParams& rhs);
	bool operator==(const CSIPHeaderParams& other) const;
	bool operator!=(const CSIPHeaderParams& other) const;
protected:
	int	m_nSize;
	ParamPair *m_pHead;
	ParamPair *m_pTail;
	ParamPair *m_pCur;
};
class BASE_API CSIPUri
{
public:
	mystring Encode();
	mystring AddressOfRecord()const;
	mystring AddressOfRecordNoScheme()const;
	void SetScheme(const char *pscheme);
	void SetHost(const char *phost);
	void SetUser(const char *puser);
	void SetPassword(const char *ppassword);
	void SetPort(int port){m_nPort = port;};
	const mystring &GetScheme()const{return m_strScheme;};
	const mystring &GetHost()const{return m_strHost;};
	int	GetPort()const{return m_nPort;};
	const mystring &GetUser()const{return m_strUser;};
	mystring &GetPassword(){return m_strPassword;};
	const mystring &GetPassword()const{return m_strPassword;};
	int Parse(const char *puri,int len,bool param=true);
	const CSIPHeaderParams &GetParams()const{return m_Params;};
	const CSIPHeaderParams &GetHeaders()const{return m_Headers;};
	CSIPHeaderParams &Params(){return m_Params;};
	CSIPHeaderParams &Headers(){return m_Headers;};
	CSIPUri(const CSIPUri &uri);
	CSIPUri();
	virtual ~CSIPUri();
	CSIPUri& operator=(const CSIPUri& rhs);
	bool operator==(const CSIPUri& other) const;
	bool operator!=(const CSIPUri& other) const;
	bool operator<(const CSIPUri& other) const;
	void Clear();
private:
	int ParseNetPath(const char *pbuf,int len);
	int ParseABSPath(const char *pbuf,int len);
	int ParseSIP(const char *pbuf,int len,bool param);
protected:
	mystring	m_strScheme;
	mystring	m_strHost;
	mystring	m_strUser;
	mystring	m_strPassword;

	int			m_nPort;
private:
	CSIPHeaderParams	m_Params;
	CSIPHeaderParams	m_Headers;
};

class BASE_API CSIPAbsoluteUri
{
public:
	class Segment{
	public:
		Segment(){m_strSegment.erase();};
		~Segment(){};
		void Clear(){m_strSegment.erase();m_Params.Clear();};
		int Parse(const char *pbody,int len);
		mystring &GetSegment(){return m_strSegment;};
		const mystring &GetSegment()const {return m_strSegment;};
		CSIPHeaderParams &GetParams(){return m_Params;};
		const CSIPHeaderParams &GetParams()const{return m_Params;};
		bool AddParam(const char *pname,const char *pvalue){return m_Params.AddParam(pname,pvalue);};
		const char *GetValue(const char *pname)const{return m_Params.GetValue(pname);};
	//	bool FindParam(const char *pname)const{return m_Params.FindParam(pname);};
		bool SetValue(const char *pname,const char *pvalue){return m_Params.SetValue(pname,pvalue);};

		mystring Encode();
		Segment& operator=(const Segment& other);
	private:
		mystring	m_strSegment;
		CSIPHeaderParams	m_Params;
	};
	void SetScheme(const char *pscheme){m_strScheme = pscheme;};
	void SetHost(const char *phost){m_strHost = phost;};
	void SetUser(const char *puser){m_strUser = puser;};
	void SetPassword(const char *ppassword){m_strPassword = ppassword;};
	void SetPort(int port){m_nPort = port;};
	const mystring &GetScheme()const{return m_strScheme;};
	const mystring &GetHost()const{return m_strHost;};
	int	GetPort()const{return m_nPort;};
	const mystring &GetUser()const{return m_strUser;};
	mystring &GetPassword(){return m_strPassword;};
	void SetQuery(const char *pquery){m_strQuery = pquery;};
	mystring &GetQuery(){return m_strQuery;};
	void SetOpaquePath(const char *popaquepath){m_strOpaquePath = popaquepath;};
	mystring &GetOpaquePath(){return m_strOpaquePath;};
	void SetRegName(const char *pregname){m_strRegName = pregname;};
	mystring &GetRegName(){return m_strRegName;};
	void AddSegment(Segment &segment){m_Segments.push_back(segment);};
	list<Segment> &GetSegments(){return m_Segments;};
	const list<Segment> &GetSegments()const {return m_Segments;};
	void Clear();
	int Parse(const char *pbody,int len);
	mystring Encode();
	CSIPAbsoluteUri();
	CSIPAbsoluteUri(const CSIPAbsoluteUri &auri);
	virtual ~CSIPAbsoluteUri();
	CSIPAbsoluteUri& operator=(const CSIPAbsoluteUri& rhs);
	bool operator!=(const CSIPAbsoluteUri& other) const{return true;};
private:
	mystring			m_strQuery;
	mystring			m_strScheme;
	mystring			m_strHost;
	mystring			m_strUser;
	mystring			m_strPassword;
	mystring			m_strRegName;
	mystring			m_strOpaquePath;
	int				m_nPort;
	list<Segment>	m_Segments;
};
class BASE_API CSIPNameAddr
{
public:
	void SetDisplayName(const char *pname);
	const mystring &GetDisplayName()const {return m_strDisplayName;};
	void SetUri(const CSIPUri &uri){m_Uri = uri;};
	const CSIPUri *GetUri()const {return &m_Uri;};
	CSIPNameAddr();
	CSIPNameAddr(const CSIPNameAddr &addr);
	CSIPNameAddr(const CSIPUri &uri){m_strDisplayName = "",m_Uri = uri;};
	virtual ~CSIPNameAddr();
	CSIPUri &Uri(){return m_Uri;};
	int Parse(const char *pbody,int len);
	mystring Encode();
//	mystring EncodeNoName();
	CSIPNameAddr& operator=(const CSIPNameAddr& rhs);
	bool operator==(const CSIPNameAddr& other) const;
	bool operator!=(const CSIPNameAddr& other) const;

	void Clear();
protected:
	mystring			m_strDisplayName;
	CSIPUri			m_Uri;
};
class BASE_API CSIPHeader  
{
public:
	enum Type{
		UNKNOWN = -1,
		//====================
		// Token:
		//====================
		ContentDisposition,// "Content-Disposition", Token);
		ContentEncoding, //"Content-Encoding", Token);
		ContentTransferEncoding,// "Content-Transfer-Encoding", StringCategory);
		MIMEVersion,// "Mime-Version", Token);
		Priority,// "Priority", Token);
		Event,// "Event", Token);
		AllowEvents,// "Allow-Events", Token);
		// explicitly declare to avoid h_AllowEventss, ugh
		AcceptEncoding,// "Accept-Encoding", Token);
		AcceptLanguage,// "Accept-Language", Token);
		Allow,// "Allow", Token);
		ContentLanguage,// "Content-Language", Token);
		ProxyRequire,// "Proxy-Require", Token);
		Require,// "Require", Token);
		Supported,// "Supported", Token);
		SubscriptionState,// "Subscription-State", Token);
		Unsupported,// "Unsupported", Token);
		SecurityClient,// "Security-Client", Token);
		SecurityServer,// "Security-Server", Token);
		SecurityVerify,// "Security-Verify", Token);
		//====================
		// Mime
		//====================
		Accept,// "Accept", Mime);
		ContentType,// "Content-Type", Mime);
		//====================
		// GenericURIs:
		//====================
		CallInfo,// "Call-Info", GenericURI);
		AlertInfo,// "Alert-Info", GenericURI);
		ErrorInfo,// "Error-Info", GenericURI);
		//====================
		// NameAddr:
		//====================
		RecordRoute,// "Record-Route", NameAddr);
		Route,// "Route", NameAddr);
		Contact,// "Contact", NameAddr);
		From,// "From", NameAddr);
		To,// "To", NameAddr);
		ReplyTo,// "Reply-To", NameAddr);
		ReferTo,// "Refer-To", NameAddr);
		ReferredBy,// "Referred-By", NameAddr);
		//====================
		// String:
		//====================
		Organization,// "Organization", StringCategory);
		Server,// "Server", StringCategory);
		Subject,// "Subject", StringCategory);
		UserAgent,// "User-Agent", StringCategory);
		Timestamp,// "Timestamp", StringCategory);
		//====================
		// Integer:
		//====================
		// !dlb! not clear this needs to be exposed
		ContentLength,// "Content-Length", IntegerCategory);
		MaxForwards,// "Max-Forwards", IntegerCategory);
		MinExpires,// "Min-Expires", IntegerCategory);
		// !dlb! this one is not quite right -- can have (comment) after field value
		RetryAfter,// "Retry-After", IntegerCategory);
		Expires,// "Expires", ExpiresCategory);
		//====================
		// CallId:
		//====================
		CallId,// "Call-ID", CallId);
		Replaces,// "Replaces", CallId);
		InReplyTo,// "In-Reply-To", CallId);
		//====================
		// Auth:
		//====================	
		AuthenticationInfo,// "Authentication-Info", Auth);
		Authorization,// "Authorization", Auth);
		ProxyAuthenticate,// "Proxy-Authenticate", Auth);
		ProxyAuthorization,// "Proxy-Authorization", Auth);
		WWWAuthenticate,// "Www-Authenticate", Auth);
		//====================
		// SequenceCategory:
		//====================
		CSeq,//"Sequence", SequenceCategory);
		//====================
		// DateCategory:
		//====================
		Date,// "Date", DateCategory);
		//====================
		// WarningCategory:
		//====================
		Warning,// "Warning", WarningCategory);
		//====================
		// Via
		//====================	
		Via,// "Via", Via);
		Translate,
		Scale,
		Seek,
		MAX_HEADERS,
	};
	CSIPHeader();
	virtual ~CSIPHeader();
	Type GetType(){return m_eType;};
	void SetType(Type type){m_eType = type;};
	virtual int Parse(const char *pbody,int len) = 0;
	void AddParam(const char *pname,const char *pvalue,bool hasquote=false);
	const char *GetValue(const char *pname)const;
	bool FindParam(const char *pname)const;
//	bool CSIPHeader::FindParam(const char *pname)const;
	bool SetValue(const char *pname,const char *pvalue);
	virtual mystring Encode() = 0;
	virtual mystring EncodeNoName() = 0;
public:
	static char m_sHeaderNames[MAX_HEADERS][32];
protected:
	Type				m_eType;
	CSIPHeaderParams	m_Params;	
};


class BASE_API CSIPCallID:public CSIPHeader{
public:
	void Clear();
	mystring Encode();
	mystring EncodeNoName();
	const mystring& GetCallId()const{return m_strCallID;};
	int Parse(const char *pbody,int len);
	void SetCallId(const char *pcallid);
	CSIPCallID(){m_strCallID.erase();m_eType = CallId;};
	CSIPCallID(const CSIPCallID &cid);
	virtual ~CSIPCallID(){};
	CSIPCallID& operator=(const CSIPCallID& rhs);
	bool operator==(const CSIPCallID& other) const;
	bool operator!=(const CSIPCallID& other) const;
	bool operator<(const CSIPCallID& other) const;
	
protected:
	mystring	m_strCallID;
};
class CSIPSequence:public CSIPHeader{
public:
	mystring Encode();
	mystring EncodeNoName();
	void SetMethod(MethodTypes method);
	void SetMethod(const char *pmethod){m_strMethod = pmethod;};
	//const mystring &GetMethod()const{return m_strMethod;};
	MethodTypes GetMethod()const {return GetMethodType(m_strMethod.c_str());};
	int Parse(const char *pbody,int len);
	void SetSequence(unsigned Sequence){m_nSequence = Sequence;};
	unsigned GetSequence()const{return m_nSequence;};
	unsigned GetCSeq()const{return m_nSequence;};
	void Clear(){m_nSequence = 0;};
	CSIPSequence(){m_nSequence = 0;m_eType = CSeq;m_strMethod.erase();};
	CSIPSequence(const CSIPSequence &seq);
	CSIPSequence(const char *pmethod){m_eType = CSeq;m_strMethod=pmethod;};
	
	virtual ~CSIPSequence(){};
	
	CSIPSequence& operator=(const CSIPSequence& rhs);
	bool operator==(const CSIPSequence& other) const;
	bool operator!=(const CSIPSequence& other) const;
	bool operator<(const CSIPSequence& other) const;

protected:
	unsigned 	m_nSequence;
	mystring		m_strMethod;
};

class BASE_API CSIPTo:public CSIPHeader
{
public:
	void SetDisplayName(const char *pname);
	const mystring &GetDisplayName()const {return m_NameAddr.GetDisplayName();};
	void SetNameAddr(const CSIPNameAddr &uri){m_NameAddr = uri;};
	const CSIPNameAddr &GetNameAddr()const {return m_NameAddr;};
	CSIPNameAddr &GetNameAddr(){return m_NameAddr;};
	int Parse(const char *pbody,int len);
	mystring Encode();
	mystring EncodeNoName();
	CSIPTo& operator=(const CSIPTo& rhs);
	bool operator==(const CSIPTo& other) const;
	bool operator!=(const CSIPTo& other) const;

	void Clear();

	CSIPTo();
	CSIPTo(CSIPNameAddr &addr){m_NameAddr = addr;};
	CSIPTo(const CSIPTo &to);
	virtual ~CSIPTo();
private:
	CSIPNameAddr	m_NameAddr;
};


class BASE_API CSIPFrom:public CSIPHeader
{
public:
	void SetDisplayName(const char *pname);
	const mystring &GetDisplayName()const {return m_NameAddr.GetDisplayName();};
	void SetNameAddr(const CSIPNameAddr &uri){m_NameAddr = uri;};
	const CSIPNameAddr &GetNameAddr()const {return m_NameAddr;};
	CSIPNameAddr &GetNameAddr(){return m_NameAddr;};
	int Parse(const char *pbody,int len);
	mystring Encode();
	mystring EncodeNoName();
	CSIPFrom& operator=(const CSIPFrom& rhs);
	bool operator==(const CSIPFrom& other) const;
	bool operator!=(const CSIPFrom& other) const;

	void Clear();

	CSIPFrom();
	CSIPFrom(CSIPNameAddr &addr){m_NameAddr = addr;};
	CSIPFrom(const CSIPFrom &to);
	virtual ~CSIPFrom();
private:
	CSIPNameAddr	m_NameAddr;
};

class BASE_API CSIPVia : public CSIPHeader  
{
public:	
	void SetProtocolName(const char *proname){m_strProtocolName = proname;};
	void SetProtocolVersion(const char *pver){m_strProtocolVersion = pver;};
	void SetTransport(const char *ptran){m_strTransport = ptran;};
	void SetHost(const char *phost);
	void SetPort(int port){m_nPort = port;};
	void AddBranch(const char *pbranch){AddParam("branch",pbranch);};
	const char *GetBranch(){return GetValue("branch");};	
	mystring Encode();
	mystring EncodeNoName();
	mystring &GetHost(){return m_strHost;};
	mystring &GetProtocolName(){return m_strProtocolName;};
	mystring &GetProtocolVersion(){return m_strProtocolVersion;};
	mystring &GetTransport(){return m_strTransport;};
	int GetPort(){return m_nPort;};
	int Parse(const char *pbody,int len);
	CSIPVia();
	
	CSIPVia(const CSIPVia &via);
	virtual ~CSIPVia();

	CSIPVia& operator=(const CSIPVia& rhs);
	bool operator==(const CSIPVia& other) const;
	bool operator!=(const CSIPVia& other) const;
//	bool operator<(const CSIPVia& other) const;
private:
	int SubParse(const char *pbody,int len);
	int PrivateParse(const char *pbody,int len);
	void Clear();
protected:
	mystring				m_strProtocolVersion;
	mystring				m_strProtocolName;
	mystring				m_strTransport;
	mystring				m_strHost;
	int					m_nPort;	
	bool				m_bNewLine;
};


class BASE_API CSIPExpires: public CSIPHeader
{
public:
	mystring Encode();
	mystring EncodeNoName();
	CSIPExpires(int ex = 3600){m_nExpires=ex;m_eType = Expires;};
	CSIPExpires(const CSIPExpires &ex){*this = ex;};
	virtual ~CSIPExpires(){};
	void SetExpires(int expires){m_nExpires = expires;};
	int GetExpires()const{return m_nExpires;};
	CSIPExpires& operator=(const CSIPExpires& rhs);
	bool operator==(const CSIPExpires& other) const;
	bool operator!=(const CSIPExpires& other) const;
	bool operator<(const CSIPExpires& other) const;
	int Parse(const char *pbody,int len);
protected:
	int	m_nExpires;
};
class BASE_API CSIPMinExpires: public CSIPHeader
{
public:
	mystring Encode();
	mystring EncodeNoName();
	CSIPMinExpires(const CSIPMinExpires &min){*this = min;};
	CSIPMinExpires(){m_nMinExpires=0;m_eType=MinExpires;};
	virtual ~CSIPMinExpires(){};
	void SetMinExpires(int expires){m_nMinExpires = expires;};
	int GetMinExpires()const{return m_nMinExpires;};
	CSIPMinExpires& operator=(const CSIPMinExpires& rhs);
	bool operator==(const CSIPMinExpires& other) const;
	bool operator!=(const CSIPMinExpires& other) const;
	bool operator<(const CSIPMinExpires& other) const;
	int Parse(const char *pbody,int len);
protected:
	int	m_nMinExpires;
};

class BASE_API CSIPSupported: public CSIPHeader
{
public:
	mystring Encode();
	mystring EncodeNoName();
	CSIPSupported(const CSIPSupported &min){*this = min;};
	CSIPSupported(){m_eType=Supported;};
	virtual ~CSIPSupported();
	mystring &GetOptionTag(){return m_strOptionTag;};
	const mystring &GetOptionTag()const{return m_strOptionTag;};
	void SetOptionTag(const char *ptag){m_strOptionTag = ptag;};

	CSIPSupported& operator=(const CSIPSupported& rhs);
	bool operator==(const CSIPSupported& other) const;
	bool operator!=(const CSIPSupported& other) const;
	bool operator<(const CSIPSupported& other) const;
	int Parse(const char *pbody,int len);
protected:	
	mystring		m_strOptionTag;
};


class BASE_API CSIPProxyRequire: public CSIPHeader
{
public:
	mystring Encode();
	mystring EncodeNoName();
	CSIPProxyRequire(const CSIPProxyRequire &min){*this = min;};
	CSIPProxyRequire(){m_eType=ProxyRequire;};
	virtual ~CSIPProxyRequire();
	mystring &GetOptionTag(){return m_strOptionTag;};
	const mystring &GetOptionTag()const{return m_strOptionTag;};
	void SetOptionTag(const char *ptag){m_strOptionTag = ptag;};

	CSIPProxyRequire& operator=(const CSIPProxyRequire& rhs);
	bool operator==(const CSIPProxyRequire& other) const;
	bool operator!=(const CSIPProxyRequire& other) const;
	bool operator<(const CSIPProxyRequire& other) const;
	int Parse(const char *pbody,int len);
protected:	
	mystring		m_strOptionTag;
};
class BASE_API CSIPMaxForwards: public CSIPHeader
{
public:
	mystring Encode();
	mystring EncodeNoName();
	CSIPMaxForwards(int ex = 70){m_nMaxForwards=ex;m_eType = MaxForwards;};
	CSIPMaxForwards(const CSIPMaxForwards &ex){*this = ex;};
	virtual ~CSIPMaxForwards(){};
	void SetMaxForwards(int MaxForwards){m_nMaxForwards = MaxForwards;};
	int GetMaxForwards()const {return m_nMaxForwards;};
	int Decrease(){m_nMaxForwards--;return m_nMaxForwards;};
	CSIPMaxForwards& operator=(const CSIPMaxForwards& rhs);
	bool operator==(const CSIPMaxForwards& other) const;
	bool operator!=(const CSIPMaxForwards& other) const;
	bool operator<(const CSIPMaxForwards& other) const;
	int Parse(const char *pbody,int len);
protected:
	int	m_nMaxForwards;
};


class BASE_API CSIPContentLength: public CSIPHeader
{
public:
	mystring Encode();
	mystring EncodeNoName();
	CSIPContentLength(int ex = 0){m_nContentLength=ex;m_eType = ContentLength;};
	CSIPContentLength(const CSIPContentLength &ex){*this = ex;};
	virtual ~CSIPContentLength(){};
	void SetContentLength(int ContentLength){m_nContentLength = ContentLength;};
	int GetContentLength(){return m_nContentLength;};
	CSIPContentLength& operator=(const CSIPContentLength& rhs);
	bool operator==(const CSIPContentLength& other) const;
	bool operator!=(const CSIPContentLength& other) const;
	bool operator<(const CSIPContentLength& other) const;
	int Parse(const char *pbody,int len);
protected:
	int	m_nContentLength;
};

class BASE_API CSIPIPAddress:public CSIPHeader
{
public:
	CSIPIPAddress();
	CSIPIPAddress(const CSIPIPAddress &a);
	virtual ~CSIPIPAddress();
	virtual mystring Encode();
	virtual mystring EncodeNoName();
	int Parse(const char *pbody,int len);
	CSIPIPAddress& operator=(const CSIPIPAddress& rhs);
	bool operator==(const CSIPIPAddress &other) const;
	bool operator!=(const CSIPIPAddress &other) const;
	void Clear();
	void SetIPAddress(const char *paddr)
	{m_strIPAddress = paddr;};
	void SetPort(int port){m_nPort = port;};
	int GetPort()const{return m_nPort;};
	mystring &GetIPAddress(){return m_strIPAddress;};
	const mystring& GetIPAddress()const{return m_strIPAddress;};
protected:
	mystring	m_strIPAddress;
	int			m_nPort;
};
class BASE_API CSIPNATAddress:public CSIPIPAddress
{
public:
	CSIPNATAddress(){};
	CSIPNATAddress(const CSIPNATAddress &a)
	{
		*this = a;
	};
	virtual ~CSIPNATAddress(){};
	mystring Encode()
	{
		mystring en;
		en = "NATAddress: ";
		en += m_strIPAddress;
		en += " ";
		en += m_nPort;
		return en;
	}
	
	//int Parse(const char *pbody,int len);
	//CSIPNATAddress& operator=(const CSIPNATAddress& rhs);
	//bool operator==(const CSIPNATAddress &other) const;
	//bool operator!=(const CSIPNATAddress &other) const;
	//void Clear();
	void SetNATAddress(const char *paddr)
	{m_strIPAddress = paddr;};
	void SetNATPort(int port){m_nPort = port;};
	int GetNATPort()const{return m_nPort;};
	mystring &GetNATAddress(){return m_strIPAddress;};
	const mystring& GetNATAddress()const{return m_strIPAddress;};
private:

};

class BASE_API CSIPContact:public CSIPHeader
{
public:
	CSIPContact();
	CSIPContact(bool all){m_bAsterisk = all;};
	CSIPContact(const CSIPContact &c);
	CSIPContact(const CSIPNameAddr &na){m_bAsterisk=false,m_NameAddr = na;};
	virtual ~CSIPContact();
	int Parse(const char *pbody,int len);
	mystring Encode();
	void SetAll(bool b){m_bAsterisk = b;};
	bool IsAll()const {return m_bAsterisk;};	
	void SetNameAddr(const CSIPNameAddr &na){m_NameAddr = na;};
	CSIPContact& operator=(const CSIPContact& rhs);
	bool operator==(const CSIPContact& other) const;
	bool operator!=(const CSIPContact& other) const;	
	mystring EncodeNoName();
	void Clear();
	CSIPNameAddr &NameAddr(){return m_NameAddr;};
	const CSIPNameAddr &NameAddr()const{return m_NameAddr;};
	CSIPNameAddr *GetNameAddr(){return &m_NameAddr;};
	const CSIPNameAddr *GetNameAddr()const{return &m_NameAddr;};
protected:
	bool				m_bAsterisk;
	CSIPNameAddr		m_NameAddr;
};

class BASE_API CSIPContentType:public CSIPHeader
{
public:
	CSIPContentType();
	CSIPContentType(const CSIPContentType &ct);
	CSIPContentType(const char *ptype,const char *psubtype);
	virtual ~CSIPContentType();
	CSIPContentType& operator=(const CSIPContentType& rhs);
	bool operator==(const CSIPContentType& other) const;
	bool operator!=(const CSIPContentType& other) const;

	int Parse(const char *pbody,int len);
	mystring Encode();
	mystring EncodeNoName();
	void SetType(const char *ptype);
	void SetSubType(const char *psubtype);
	const mystring &GetType()const {return m_strType;};
	const mystring &GetSubType()const {return m_strSubType;};
	void Clear();
protected:
	mystring				m_strType;
	mystring				m_strSubType;
};
class BASE_API CSIPContentLanguage:public CSIPHeader
{
public:
	CSIPContentLanguage();
	CSIPContentLanguage(const CSIPContentLanguage &ct);
	virtual ~CSIPContentLanguage();
	CSIPContentLanguage& operator=(const CSIPContentLanguage& rhs);
	//bool operator==(const CSIPContentLanguage& other) const;
//	bool operator!=(const CSIPContentLanguage& other) const;
	
	int Parse(const char *pbody,int len);
	mystring Encode();
	mystring EncodeNoName();
	void Clear();
	mystring &GetContentLanguage(){return m_strContentLanguage;};
	const mystring &GetContentLanguage()const{return m_strContentLanguage;};
	void SetContentLanguage(const char *pcoding){m_strContentLanguage = pcoding;};
protected:	
	mystring		m_strContentLanguage;
};
class BASE_API CSIPContentEncoding:public CSIPHeader
{
public:
	CSIPContentEncoding();
	CSIPContentEncoding(const CSIPContentEncoding &ct);
	virtual ~CSIPContentEncoding();
	CSIPContentEncoding& operator=(const CSIPContentEncoding& rhs);
	bool operator==(const CSIPContentEncoding& other) const;
	bool operator!=(const CSIPContentEncoding& other) const;
	
	int Parse(const char *pbody,int len);
	mystring Encode();
	mystring EncodeNoName();
	void Clear();
	mystring &GetContentCoding(){return m_strContentCoding;};
	const mystring &GetContentCoding()const{return m_strContentCoding;};
	void SetContentCoding(const char *pcoding){m_strContentCoding = pcoding;};
protected:	
	mystring		m_strContentCoding;
};

class BASE_API CSIPContentDisposition:public CSIPHeader
{
public:
	CSIPContentDisposition();
	CSIPContentDisposition(const CSIPContentDisposition &ct);
	virtual ~CSIPContentDisposition();
	CSIPContentDisposition& operator=(const CSIPContentDisposition& rhs);
	bool operator==(const CSIPContentDisposition other) const;
	bool operator!=(const CSIPContentDisposition& other) const;
	
	int Parse(const char *pbody,int len);
	mystring Encode();
	mystring EncodeNoName();
	void Clear();
	mystring &GetDispType(){return m_strDispType;};
	const mystring &GetDispType()const{return m_strDispType;};
	void SetDispType(const char *pcoding){m_strDispType = pcoding;};
private:
	mystring	m_strDispType;
};

class BASE_API CSIPAccept:public CSIPHeader
{
public:
	class CMediaRange{
	public:
		CMediaRange();
		CMediaRange(const CMediaRange &mr);
		~CMediaRange();
		void SetType(const char *ptype){m_strType = ptype;};
		void SetSubType(const char *psubtype){m_strSubType = psubtype;};
		mystring &GetType(){return m_strType;};
		mystring &GetSubType(){return m_strSubType;};
		CMediaRange& operator=(const CMediaRange& rhs);
		void Clear();
		int Parse(const char *pbody,int len,bool param = true);
		mystring Encode();
	
		CSIPHeaderParams &GetParams(){return m_Params;};
		const CSIPHeaderParams &GetParams()const{return m_Params;};
	private:
		mystring				m_strType;
		mystring				m_strSubType;
		CSIPHeaderParams	m_Params;
		friend class CSIPAccept;
	};
	
	CSIPAccept();
	CSIPAccept(const CSIPAccept &ct);
	virtual ~CSIPAccept();
	CSIPAccept& operator=(const CSIPAccept& rhs);
	bool operator==(const CSIPAccept& other) const;
	bool operator!=(const CSIPAccept& other) const;
	int Parse(const char *pbody,int len);
	mystring Encode();
		mystring EncodeNoName();
	void Clear();
	void SetMediaRange(CMediaRange &mr){m_MediaRange = mr;};
	CMediaRange &GetMediaRange(){return m_MediaRange;};
	const CMediaRange &GetMediaRange()const{return m_MediaRange;};

protected:
	CMediaRange			m_MediaRange;
};
class BASE_API CSIPTranslate:public CSIPHeader
{
public:
	CSIPTranslate();
	CSIPTranslate(const CSIPTranslate &c);
	virtual ~CSIPTranslate();
	int Parse(const char *pbody,int len);
	mystring Encode();
	mystring EncodeNoName();
	void AddNameAddr(CSIPNameAddr &na);
	const CSIPNameAddr *GetNameAddr()const {return m_pNA;};
	CSIPTranslate& operator=(const CSIPTranslate& rhs);
	bool operator==(const CSIPTranslate& other) const;
	bool operator!=(const CSIPTranslate& other) const;
	void Clear();
protected:
	CSIPNameAddr *	m_pNA;
};
class BASE_API CSIPSubscriptionState:public CSIPHeader
{
public:
	enum States{
		unknown,
		pending,
		active,
		terminated,
		maxstates,
	};
	CSIPSubscriptionState();
	CSIPSubscriptionState(States s);
	CSIPSubscriptionState(const CSIPSubscriptionState &s);
	virtual ~CSIPSubscriptionState();
	int Parse(const char *pbody,int len);
	mystring Encode();
	mystring EncodeNoName();
	void SetState(States s){m_eState = s;};
	States GetState()const{return m_eState;};
	CSIPSubscriptionState& operator=(const CSIPSubscriptionState& rhs);
	bool operator==(const CSIPSubscriptionState& other) const;
	bool operator!=(const CSIPSubscriptionState& other) const;
	void Clear();
public:
	static char m_sStates[maxstates][11];
protected:
	States	m_eState;	
	mystring	m_strState;
};

class BASE_API CSIPContent
{
public:
	CSIPContent();
	CSIPContent(const CSIPContent &c);
	CSIPContent(const CSIPContentType &type);
	virtual ~CSIPContent();
	virtual void SetContent(const char *pcontent,int len);
	void SetContentType(const CSIPContentType &type);
	virtual mystring Encode();
	void Clear();
	int GetContentLength()const {return m_nLength;};
	const char *GetContent()const {return m_pContent;};
	CSIPContent& operator=(const CSIPContent& rhs);
	bool operator==(const CSIPContent& other) const;
	bool operator!=(const CSIPContent& other) const;
protected:
	char *	m_pContent;
	int		m_nLength;
	CSIPContentType*	m_pContentType;
};

class BASE_API CSIPEvent:public CSIPHeader
{
public:
	enum Events{
		enSubscribeMethodRegister = 0,
		enSubscribeMethodSubscribe,
		enSubscribeMethodPresence,
		enSubscribeMethodRecord,
		enSubscribeMethodHeartbeat,//must been used for subscription itself.
		enSubscribeMethodLock,
		enSubscribeMethodUnlock,
		enSubscribeMethodUnknown,
		enMaxSubscribeMethod
	};
	CSIPEvent();
	CSIPEvent(Events e);
	CSIPEvent(const CSIPEvent &e);
	virtual ~CSIPEvent();
	int Parse(const char *pbody,int len);
	mystring Encode();
	mystring EncodeNoName();
	CSIPEvent::Events GetEvent()const {return m_eEvent;};
	mystring &GetEventType(){return m_strEventType;};
	const mystring &GetEventType()const{return m_strEventType;};
	void SetEvent(Events e){m_eEvent = e;};
	CSIPEvent& operator=(const CSIPEvent& rhs);
	bool operator==(const CSIPEvent& other) const;
	bool operator!=(const CSIPEvent& other) const;
	void Clear();
public:
	static char m_sEvents[enMaxSubscribeMethod][32];
protected:
	Events		MatchEvent(mystring &str);
	mystring	m_strEventType;
	Events		m_eEvent;
};
class BASE_API CSIPAllowEvents:public CSIPHeader
{//RFC3265
public:
	CSIPAllowEvents();
	CSIPAllowEvents(const CSIPAllowEvents &e);
	virtual ~CSIPAllowEvents();
	int Parse(const char *pbody,int len);
	mystring Encode();
	mystring EncodeNoName();
	const mystring &GetEvent()const{return m_strEvent;};
	mystring &GetEvent(){return m_strEvent;};
	void SetEvent(const char *pevent){m_strEvent = pevent;};
	CSIPAllowEvents& operator=(const CSIPAllowEvents& rhs);
	bool operator==(const CSIPAllowEvents& other) const;
	bool operator!=(const CSIPAllowEvents& other) const;
	void Clear();
protected:
	mystring	m_strEvent;
};
//Request-Line  =  Method SP Request-URI SP SIP-Version CRLF
class BASE_API CSIPRequestLine
{
public:
	CSIPRequestLine(MethodTypes method = UNKNOWN);
	CSIPRequestLine(const CSIPRequestLine &line);
	virtual~CSIPRequestLine();
	int Parse(const char *pbody,int len);
	mystring Encode();
	CSIPUri &Uri(){return m_Uri;};
	const CSIPUri *GetUri()const{return &m_Uri;};
	void SetUri(const CSIPUri &uri){m_Uri = uri;};
	void SetMethod(MethodTypes method);
	void SetMethod(const char *pmethod){m_strMethod = pmethod;m_eMethod = GetMethodType(pmethod);};
	void SetSIPVersion(const char *psipversion){if(psipversion)m_strSIPVersion = psipversion;else m_strSIPVersion = "SIP/2.0";};
	mystring GetSIPVersion()const{return m_strSIPVersion;};
	MethodTypes GetMethod()const {return m_eMethod;};
	mystring &GetMethodString(){return m_strMethod;};
	const mystring &GetMethodString()const{return m_strMethod;};
	CSIPRequestLine& operator=(const CSIPRequestLine& rhs);
	
	bool operator==(const CSIPRequestLine& other) const;
	bool operator!=(const CSIPRequestLine& other) const;
private:
	void Clear();
private:
	 CSIPUri					m_Uri;
	 mystring						m_strMethod;
	 MethodTypes				m_eMethod;
	 mystring						m_strSIPVersion;
};
//Status-Line  =  SIP-Version SP Status-Code SP Reason-Phrase CRLF
class BASE_API CSIPStatusLine
{
public:
	CSIPStatusLine();
	CSIPStatusLine(const CSIPStatusLine &line);
	virtual~CSIPStatusLine();
	int Parse(const char *pbody,int len);
	mystring Encode();	
	void SetStatusCode(int code){m_nStatusCode = code;};
	void SetReason(const char *preason){if(preason)m_strReason = preason;else m_strReason = "";};
	const mystring &GetReason()const{return m_strReason;};
	void SetSIPVersion(const char *psipversion){if(psipversion)m_strSIPVersion = psipversion;else m_strSIPVersion = "SIP/2.0";};
	const mystring &GetSIPVerson()const{return m_strSIPVersion;};
	CSIPStatusLine& operator=(const CSIPStatusLine& rhs);
	int GetStatusCode()const {return m_nStatusCode;};
	bool operator==(const CSIPStatusLine& other) const;
	bool operator!=(const CSIPStatusLine& other) const;
private:
	void Clear();
private:
	int			m_nStatusCode;
	mystring		m_strReason;
	mystring		m_strSIPVersion;
};
class BASE_API CSIPUserAgent:public CSIPHeader
{
public:
	CSIPUserAgent();
	CSIPUserAgent(const char *puag);
	CSIPUserAgent(const CSIPUserAgent &e);
	virtual ~CSIPUserAgent();
	int Parse(const char *pbody,int len);
	mystring Encode();
	mystring EncodeNoName();
	void SetUserAgent(const char *puseragent){if(puseragent)m_strUserAgent = puseragent;else m_strUserAgent = "";};
	mystring &GetUserAgent(){return m_strUserAgent;};
	const mystring &GetUserAgent()const{return m_strUserAgent;};
	CSIPUserAgent& operator=(const CSIPUserAgent& rhs);
	bool operator==(const CSIPUserAgent& other) const;
	bool operator!=(const CSIPUserAgent& other) const;
	void Clear(){m_strUserAgent = "";};
private:
	mystring	m_strUserAgent;
};

class BASE_API CSIPUnknown:public CSIPHeader
{
public:
	CSIPUnknown();
	CSIPUnknown(const CSIPUnknown &e);
	virtual ~CSIPUnknown();
	int Parse(const char *pbody,int len);
	mystring Encode();
	mystring EncodeNoName();
	void SetHeaderName(const char *pname){m_sHeaderName = pname;};
	mystring GetHeaderName()const {return m_sHeaderName;};
	mystring GetHeaderValue()const{return m_sHeaderValue;};
	CSIPUnknown& operator=(const CSIPUnknown& rhs);
	bool operator==(const CSIPUnknown& other) const;
	bool operator!=(const CSIPUnknown& other) const;
	void Clear(){m_sHeaderName = "";m_sHeaderValue = "";};
private:
	mystring	m_sHeaderName;
	mystring	m_sHeaderValue;
};

class BASE_API CSIPRequire:public CSIPHeader
{
public:
	CSIPRequire();
	CSIPRequire(const CSIPRequire &e);
	virtual ~CSIPRequire();
	int Parse(const char *pbody,int len);
	mystring Encode();
	mystring EncodeNoName();
	mystring &GetOptionTag(){return m_strOptionTag;};
	const mystring &GetOptionTag()const{return m_strOptionTag;};
	void SetOptionTag(const char *ptag){m_strOptionTag = ptag;};
	CSIPRequire& operator=(const CSIPRequire& rhs);
	bool operator==(const CSIPRequire& other) const;
	bool operator!=(const CSIPRequire& other) const;
	void Clear();
private:
	mystring	m_strOptionTag;
};

class BASE_API CSIPDate:public CSIPHeader
{
public:
	CSIPDate();
	CSIPDate(const CSIPDate &date);
	virtual ~CSIPDate();
	int Parse(const char *pbody,int len);
	mystring Encode();
	mystring EncodeNoName();
	void Clear();
	long GetYear(){return m_nYear;};
	short GetMonth(){return m_nMonth;};
	short GetMDay(){return m_nMDay;};
	short GetHour(){return m_nHour;};
	short GetMinute(){return m_nMinute;};
	short GetSecond(){return m_nSecond;};
	short GetWeekDay(){return m_nWeekDay;};
	void SetYear(long year){m_nYear = year;};
	void SetMonth(short month){m_nMonth = month;};
	void SetMDay(short mday){m_nMDay = mday;};
	void SetWeekDay(short weekday){m_nWeekDay = weekday;};
	void SetHour(short hour){m_nHour = hour;};
	void SetMinute(short minute){m_nMinute = minute;};
	void SetSecond(short second){m_nSecond = second;};
	const char *GetMonthString(){return m_sMonth[m_nMonth];};
	const char *GetWeekDayString(){return m_sWeekDay[m_nWeekDay];};
	static const char *GetMonth(short month){if(month >= 0 && month < 12)return m_sMonth[month];return NULL;};
	static const char *GetWeekDay(short weekday){if(weekday >= 0 && weekday < 7)return m_sWeekDay[weekday];return NULL;};

	CSIPDate& operator=(const CSIPDate& other);
	bool operator==(const CSIPDate& other) const;
	bool operator!=(const CSIPDate& other) const;
private:
	long	m_nYear;
	short	m_nMonth;
	short	m_nMDay;
	short	m_nHour;
	short	m_nMinute;
	short	m_nSecond;
	short	m_nWeekDay;
	static char	m_sWeekDay[7][4];
	static char m_sMonth[12][4];
};

class BASE_API CSIPAllow:public CSIPHeader
{
public:
	CSIPAllow();
	CSIPAllow(const CSIPAllow &e);
	virtual ~CSIPAllow();
	int Parse(const char *pbody,int len);
	mystring Encode();
	mystring EncodeNoName();
	mystring &GetMethod(){return m_strMethod;};
	const mystring &GetMethod()const{return m_strMethod;};
	void SetMethod(const char *pmethod){m_strMethod = pmethod;};
	CSIPAllow& operator=(const CSIPAllow& rhs);
	bool operator==(const CSIPAllow &other) const;
	bool operator!=(const CSIPAllow& other) const;
	void Clear();
private:
	mystring	m_strMethod;
};

class BASE_API CSIPRoute:public CSIPHeader
{
public:
	CSIPRoute();
	CSIPRoute(const CSIPRoute &r);
	virtual ~CSIPRoute();
	mystring Encode();
	mystring EncodeNoName();
	int Parse(const char *pbody,int len);
	CSIPRoute& operator=(const CSIPRoute& rhs);
	bool operator==(const CSIPRoute &other) const;
	bool operator!=(const CSIPRoute& other) const;
	void Clear();	
	
private:
	CSIPNameAddr		m_NameAddr;
};

class BASE_API CSIPAuthorization:public CSIPHeader
{
public:	
	CSIPAuthorization();
	CSIPAuthorization(const CSIPAuthorization &a);
	virtual ~CSIPAuthorization();
	mystring Encode();
	mystring EncodeNoName();
	int Parse(const char *pbody,int len);
	CSIPAuthorization& operator=(const CSIPAuthorization& rhs);
	bool operator==(const CSIPAuthorization &other) const;
	bool operator!=(const CSIPAuthorization& other) const;
	void Clear();	
	void SetRealm(const char *prm){m_strRealm = prm;};
	void SetUserName(const char *pdomain){m_strUserName = pdomain;};
	void SetNonce(const char *pnonce){m_strNonce = pnonce;};
	void SetQop(const char *pqop){m_strQop = pqop;};
	mystring &GetRealm(){return m_strRealm;};
	const mystring &GetRealm()const{return m_strRealm;};
	
	mystring &GetUserName(){return m_strUserName;};
	const mystring &GetUserName()const{return m_strUserName;};
	mystring &GetNonce(){return m_strNonce;};
	const mystring &GetNonce()const{return m_strNonce;};
	
	mystring &GetQop(){return m_strQop;};
	const mystring &GetQop()const {return m_strQop;};

	void SetDigestUri(const char *puri){m_strDigestUri = puri;};
	mystring &GetDigestUri(){return m_strDigestUri;};
	const mystring &GetDigestUri()const{return m_strDigestUri;};
	void SetResponse(const char *presp){m_strResponse = presp;};
	mystring &GetResponse(){return m_strResponse;};
	const mystring &GetResponse()const {return m_strResponse;};
	void SetOpaque(const char *popa){m_strOpaque = popa;};
private:
	mystring	m_strUserName;
	mystring	m_strDigestUri;
	mystring	m_strQop;
	mystring	m_strCNonce;
	mystring	m_strNonceCount;
	mystring	m_strResponse;
	mystring	m_strRealm;
	mystring	m_strNonce;
	mystring	m_strOpaque;
	mystring	m_strAlgorithm;
};
class BASE_API CSIPProxyAuthorization:public CSIPHeader
{
public:	
	CSIPProxyAuthorization();
	CSIPProxyAuthorization(const CSIPProxyAuthorization &a);
	virtual ~CSIPProxyAuthorization();
	mystring Encode();
	mystring EncodeNoName();
	int Parse(const char *pbody,int len);
	CSIPProxyAuthorization& operator=(const CSIPProxyAuthorization& rhs);
	bool operator==(const CSIPProxyAuthorization &other) const;
	bool operator!=(const CSIPProxyAuthorization& other) const;
	void Clear();	
	void SetRealm(const char *prm){m_strRealm = prm;};
	void SetUserName(const char *pdomain){m_strUserName = pdomain;};
	void SetNonce(const char *pnonce){m_strNonce = pnonce;};
	void SetQop(const char *pqop){m_strQop = pqop;};
	mystring &GetRealm(){return m_strRealm;};
	const mystring &GetRealm()const{return m_strRealm;};
	
	mystring &GetUserName(){return m_strUserName;};
	const mystring &GetUserName()const{return m_strUserName;};
	mystring &GetNonce(){return m_strNonce;};
	const mystring &GetNonce()const{return m_strNonce;};
	
	mystring &GetQop(){return m_strQop;};
	const mystring &GetQop()const {return m_strQop;};

	void SetDigestUri(const char *puri){m_strDigestUri = puri;};
	void SetResponse(const char *presp){m_strResponse = presp;};
	void SetOpaque(const char *popa){m_strOpaque = popa;};
private:
	mystring	m_strUserName;
	mystring	m_strDigestUri;
	mystring	m_strQop;
	mystring	m_strCNonce;
	mystring	m_strNonceCount;
	mystring	m_strResponse;
	mystring	m_strRealm;
	mystring	m_strNonce;
	mystring	m_strOpaque;
};
class BASE_API CSIPWWWAuthenticate:public CSIPHeader
{
public:
	CSIPWWWAuthenticate();
	CSIPWWWAuthenticate(const CSIPWWWAuthenticate &a);
	virtual ~CSIPWWWAuthenticate();
	mystring Encode();
	mystring EncodeNoName();
	int Parse(const char *pbody,int len);
	CSIPWWWAuthenticate& operator=(const CSIPWWWAuthenticate& rhs);
	bool operator==(const CSIPWWWAuthenticate &other) const;
	bool operator!=(const CSIPWWWAuthenticate& other) const;
	void Clear();	
	void SetRealm(const char *prm){m_strRealm = prm;};
	void SetDomain(const char *pdomain){m_strDomain = pdomain;};
	void SetNonce(const char *pnonce){m_strNonce = pnonce;};
	void SetOpaque(const char *popaque){m_strOpaque = popaque;};
	void SetStale(const char *pstale){m_strStale = pstale;};
	void SetAlgorithm(const char *palgorithm){m_strAlgorithm = palgorithm;};
	void SetQop(const char *pqop){m_strQop = pqop;};
	mystring &GetRealm(){return m_strRealm;};
	const mystring &GetRealm()const{return m_strRealm;};
	mystring &GetDomain(){return m_strDomain;};
	const mystring &GetDomain()const{return m_strDomain;};
	mystring &GetNonce(){return m_strNonce;};
	const mystring &GetNonce()const{return m_strNonce;};
	mystring &GetOpaque(){return m_strOpaque;};
	const mystring &GetOpaque()const{return m_strOpaque;};
	mystring &GetStale(){return m_strStale;};
	const mystring &GetStale()const{return m_strStale;};
	mystring &GetAlgorithm(){return m_strAlgorithm;};
	const mystring &GetAlgorithm()const{return m_strAlgorithm;};
	mystring &GetQop(){return m_strQop;};
	const mystring &GetQop()const {return m_strQop;};
private:
	mystring	m_strRealm;
	mystring	m_strDomain;
	mystring	m_strNonce;
	mystring	m_strOpaque;
	mystring	m_strStale;
	mystring	m_strAlgorithm;
	mystring	m_strQop;
};

class BASE_API CSIPMIMEVersion:public CSIPHeader
{
public:
	CSIPMIMEVersion();
	CSIPMIMEVersion(const CSIPMIMEVersion &a);
	virtual ~CSIPMIMEVersion();
	mystring Encode();
	mystring EncodeNoName();
	int Parse(const char *pbody,int len);
	CSIPMIMEVersion& operator=(const CSIPMIMEVersion& rhs);
	bool operator==(const CSIPMIMEVersion &other) const;
	bool operator!=(const CSIPMIMEVersion &other) const;
	void Clear();
	void SetMIMEVersion(const char *pversion){m_strVersion = pversion;};
	mystring &GetMIMEVersion(){return m_strVersion;};
	const mystring &GetMIMEVersion()const{return m_strVersion;};
private:
	mystring	m_strVersion;
};   

class BASE_API CSIPAcceptEncoding:public CSIPHeader
{
public:
	CSIPAcceptEncoding();
	CSIPAcceptEncoding(const CSIPAcceptEncoding &a);
	virtual ~CSIPAcceptEncoding();
	mystring Encode();
	mystring EncodeNoName();
	int Parse(const char *pbody,int len);
	CSIPAcceptEncoding& operator=(const CSIPAcceptEncoding& rhs);
	bool operator==(const CSIPAcceptEncoding &other) const;
	bool operator!=(const CSIPAcceptEncoding &other) const;
	void Clear();
	void SetCodings(const char *pversion){m_strCodings = pversion;};
	mystring &GetCodings(){return m_strCodings;};
	const mystring &GetCodings()const{return m_strCodings;};
private:
	mystring	m_strCodings;
};

class BASE_API CSIPAcceptLanguage:public CSIPHeader
{
public:
	CSIPAcceptLanguage();
	CSIPAcceptLanguage(const CSIPAcceptLanguage &a);
	virtual ~CSIPAcceptLanguage();
	mystring Encode();
	mystring EncodeNoName();
	int Parse(const char *pbody,int len);
	CSIPAcceptLanguage& operator=(const CSIPAcceptLanguage& rhs);
	bool operator==(const CSIPAcceptLanguage &other) const;
	bool operator!=(const CSIPAcceptLanguage &other) const;
	void Clear();
	void SetLanguage(const char *pversion){m_strLanguage = pversion;};
	mystring &GetLanguage(){return m_strLanguage;};
	const mystring &GetLanguage()const{return m_strLanguage;};
private:
	mystring	m_strLanguage;
};


class BASE_API CSIPProxyAuthenticate:public CSIPHeader
{
public:	
	CSIPProxyAuthenticate();
	CSIPProxyAuthenticate(const CSIPProxyAuthenticate &a);
	virtual ~CSIPProxyAuthenticate();
	mystring Encode();
	mystring EncodeNoName();
	int Parse(const char *pbody,int len);
	CSIPProxyAuthenticate& operator=(const CSIPProxyAuthenticate& rhs);
	bool operator==(const CSIPProxyAuthenticate &other) const;
	bool operator!=(const CSIPProxyAuthenticate &other) const;
	void Clear();	
	void SetRealm(const char *prm){m_strRealm = prm;};
	void SetDomain(const char *pdomain){m_strDomain = pdomain;};
	void SetNonce(const char *pnonce){m_strNonce = pnonce;};
	void SetOpaque(const char *popaque){m_strOpaque = popaque;};
	void SetStale(const char *pstale){m_strStale = pstale;};
	void SetAlgorithm(const char *palgorithm){m_strAlgorithm = palgorithm;};
	void SetQop(const char *pqop){m_strQop = pqop;};
	mystring &GetRealm(){return m_strRealm;};
	const mystring &GetRealm()const{return m_strRealm;};
	mystring &GetDomain(){return m_strDomain;};
	const mystring &GetDomain()const{return m_strDomain;};
	mystring &GetNonce(){return m_strNonce;};
	const mystring &GetNonce()const{return m_strNonce;};
	mystring &GetOpaque(){return m_strOpaque;};
	const mystring &GetOpaque()const{return m_strOpaque;};
	mystring &GetStale(){return m_strStale;};
	const mystring &GetStale()const{return m_strStale;};
	mystring &GetAlgorithm(){return m_strAlgorithm;};
	const mystring &GetAlgorithm()const{return m_strAlgorithm;};
	mystring &GetQop(){return m_strQop;};
	const mystring &GetQop()const {return m_strQop;};
	void SetAuthParam(const char *pap){m_strAuthParam = pap;};
	mystring &GetAuthParam(){return m_strAuthParam;};
	const mystring &GetAuthParam()const{return m_strAuthParam;};
private:
	mystring	m_strRealm;
	mystring	m_strDomain;
	mystring	m_strNonce;
	mystring	m_strOpaque;
	mystring	m_strStale;
	mystring	m_strAlgorithm;
	mystring	m_strQop;
	mystring	m_strAuthParam;
	mystring	m_strAuthParamName;
};
//#ifdef PC_CLIENT
class BASE_API CSIPFileName:public CSIPHeader
{
public:
	CSIPFileName();
	CSIPFileName(const CSIPFileName &a);
	virtual ~CSIPFileName();
	mystring Encode();
	mystring EncodeNoName();
	int Parse(const char *pbody,int len);
	CSIPFileName& operator=(const CSIPFileName& rhs);
	bool operator==(const CSIPFileName &other) const;
	bool operator!=(const CSIPFileName &other) const;
	void Clear();
	void SetFileName(const char *pfilename)
	{m_strFileName = pfilename;};	
	mystring &GetWebAddress(){return m_strFileName;};
	const mystring& GetFileName()const{return m_strFileName;};
private:
	mystring	m_strFileName;
};
class BASE_API CSIPWebAddress:public CSIPIPAddress
{
public:
	CSIPWebAddress(){};
	CSIPWebAddress(const CSIPWebAddress &a)
	{
		*this = a;
	};
	virtual ~CSIPWebAddress(){};
	mystring Encode()
	{
		mystring en;
		en = "Web-Address: ";
		en += m_strIPAddress;
		en += " ";
		en += m_nPort;
		return en;
	}
	
	void SetWebAddress(const char *paddr)
	{m_strIPAddress = paddr;};
	void SetWebPort(int port){m_nPort = port;};
	int GetWebPort()const{return m_nPort;};
	mystring &GetWebAddress(){return m_strIPAddress;};
	const mystring& GetWebAddress()const{return m_strIPAddress;};
private:	
};
class BASE_API CSIPSNTPAddress:public CSIPIPAddress
{
public:
	CSIPSNTPAddress(){};
	CSIPSNTPAddress(const CSIPSNTPAddress &a)
	{
		*this = a;
	};
	virtual ~CSIPSNTPAddress(){};
	mystring Encode()
	{
		mystring en;
		en = "SNTP-Address: ";
		en += m_strIPAddress;
		en += " ";
		en += m_nPort;
		return en;
	}
	
	void SetSNTPAddress(const char *paddr)
	{m_strIPAddress = paddr;};
	void SetSNTPPort(int port){m_nPort = port;};
	int GetSNTPPort()const{return m_nPort;};
	mystring &GetSNTPAddress(){return m_strIPAddress;};
	const mystring& GetSNTPAddress()const{return m_strIPAddress;};

};

class BASE_API CSIPAlertInfo:public CSIPHeader
{
public:
	CSIPAlertInfo();
	CSIPAlertInfo(const CSIPAlertInfo &a);
	virtual ~CSIPAlertInfo();
	mystring Encode();
	mystring EncodeNoName();
	int Parse(const char *pbody,int len);
	CSIPAlertInfo& operator=(const CSIPAlertInfo& rhs);
	bool operator==(const CSIPAlertInfo &other) const;
	bool operator!=(const CSIPAlertInfo &other) const;
	void Clear();
	void SetAbsoluteUri(const CSIPAbsoluteUri &auri){m_AbsoluteUri = auri;};
	CSIPAbsoluteUri &GetAbsolute(){return m_AbsoluteUri;};
	const CSIPAbsoluteUri &GetAbsolute()const{return m_AbsoluteUri;};
private:
	CSIPAbsoluteUri	m_AbsoluteUri;
};

class BASE_API CSIPAuthenticationInfo:public CSIPHeader
{
public:
	CSIPAuthenticationInfo();
	CSIPAuthenticationInfo(const CSIPAuthenticationInfo &a);
	virtual ~CSIPAuthenticationInfo();
	mystring Encode();
	mystring EncodeNoName();
	int Parse(const char *pbody,int len);
	CSIPAuthenticationInfo& operator=(const CSIPAuthenticationInfo& rhs);
	bool operator==(const CSIPAuthenticationInfo &other) const;
	bool operator!=(const CSIPAuthenticationInfo &other) const;
	void Clear();
	
	void SetNextNonce(const char *pnonce){m_strNextNonce = pnonce;};	
	
	void SetMessageQop(const char *pqop){m_strMessageQop = pqop;};
		
	mystring &GetNextNonce(){return m_strNextNonce;};
	const mystring &GetNextNonce()const{return m_strNextNonce;};	
	mystring &GetMessageQop(){return m_strMessageQop;};
	const mystring &GetMessageQop()const {return m_strMessageQop;};

	void SetResponseAuth(const char *presa){m_strResponseAuth = presa;};
	mystring &GetResponseAuth(){return m_strResponseAuth;};
	const mystring &GetResponseAuth()const{return m_strResponseAuth;};
	
	void SetCNonce(const char *pcn){m_strCNonce = pcn;};
	mystring &GetCNonce(){return m_strCNonce;};
	const mystring &GetCNonce()const{return m_strCNonce;};

	void SetNonceCount(const char *pnc){m_strNonceCount = pnc;};
	mystring &GetNonceCount(){return m_strNonceCount;};
	const mystring &GetNonceCount()const{return m_strNonceCount;};

private:	
	mystring	m_strNonce;	
	mystring	m_strMessageQop;
	mystring	m_strNextNonce;
	mystring	m_strResponseAuth;
	mystring	m_strCNonce;
	mystring	m_strNonceCount;
};
class BASE_API CSIPServer:public CSIPHeader
{
public:
	struct ServerVal{
		bool comment;
		mystring val;
	};
	CSIPServer();
	CSIPServer(const CSIPServer &a);
	virtual ~CSIPServer();
	mystring Encode();
	mystring EncodeNoName();
	int Parse(const char *pbody,int len);
	CSIPServer& operator=(const CSIPServer& rhs);
	bool operator==(const CSIPServer &other) const;
	bool operator!=(const CSIPServer& other) const;
	void Clear();
	list<struct ServerVal> &GetServerValList(){return m_ServerValList;};
	const list<struct ServerVal> &GetServerValList()const{return m_ServerValList;};
private:
	list<struct ServerVal>	m_ServerValList;	
};

class BASE_API CSIPReplyTo:public CSIPHeader
{
public:
	void SetDisplayName(const char *pname);
	const mystring &GetDisplayName()const {return m_NameAddr.GetDisplayName();};
	void SetNameAddr(const CSIPNameAddr &uri){m_NameAddr = uri;};
	const CSIPNameAddr &GetNameAddr()const {return m_NameAddr;};
	CSIPNameAddr &GetNameAddr(){return m_NameAddr;};
	int Parse(const char *pbody,int len);
	mystring Encode();
	mystring EncodeNoName();
	CSIPReplyTo& operator=(const CSIPReplyTo& rhs);
	bool operator==(const CSIPReplyTo& other) const;
	bool operator!=(const CSIPReplyTo& other) const;

	void Clear();

	CSIPReplyTo();
	CSIPReplyTo(CSIPNameAddr &addr){m_NameAddr = addr;};
	CSIPReplyTo(const CSIPReplyTo &to);
	virtual ~CSIPReplyTo();
private:
	CSIPNameAddr	m_NameAddr;
};

class BASE_API CSIPRetryAfter:public CSIPHeader
{
public:
	CSIPRetryAfter();
	CSIPRetryAfter(const CSIPRetryAfter &a);
	virtual ~CSIPRetryAfter();
	mystring Encode();
	mystring EncodeNoName();
	int Parse(const char *pbody,int len);
	CSIPRetryAfter& operator=(const CSIPRetryAfter& rhs);
	bool operator==(const CSIPRetryAfter &other) const;
	bool operator!=(const CSIPRetryAfter &other) const;
	void Clear();
	void SetDelta(int seconds){m_nDelta = seconds;};
	int GetDelta(){return m_nDelta;};
	int GetDelta()const{return m_nDelta;};
	void SetComment(const char *pcmt){m_strComment = pcmt;};
	mystring &GetComment(){return m_strComment;};
	const mystring &GetComment()const{return m_strComment;};
private:
	int		m_nDelta;
	mystring	m_strComment;
};

class BASE_API CSIPSubject:public CSIPHeader
{
public:
	CSIPSubject();
	CSIPSubject(const CSIPSubject &a);
	virtual ~CSIPSubject();
	mystring Encode();
	mystring EncodeNoName();
	int Parse(const char *pbody,int len);
	CSIPSubject& operator=(const CSIPSubject& rhs);
	bool operator==(const CSIPSubject &other) const;
	bool operator!=(const CSIPSubject &other) const;
	void Clear();
	void SetSubject(const char *pSubject){m_strSubject = pSubject;};
	mystring &GetSubject(){return m_strSubject;};
	const mystring &GetSubject()const{return m_strSubject;};
private:
	mystring	m_strSubject;
};

class BASE_API CSIPTimestamp:public CSIPHeader
{
public:
	CSIPTimestamp();
	CSIPTimestamp(const CSIPTimestamp &a);
	virtual ~CSIPTimestamp();
	mystring Encode();
	mystring EncodeNoName();
	int Parse(const char *pbody,int len);
	CSIPTimestamp& operator=(const CSIPTimestamp& rhs);
	bool operator==(const CSIPTimestamp &other) const;
	bool operator!=(const CSIPTimestamp &other) const;
	void Clear();
	void SetTimestamp(const char *pversion){m_strTimestamp = pversion;};
	mystring &GetTimestamp(){return m_strTimestamp;};
	const mystring &GetTimestamp()const{return m_strTimestamp;};

	void SetDelay(const char *pversion){m_strDelay = pversion;};
	mystring &GetDelay(){return m_strDelay;};
	const mystring &GetDelay()const{return m_strDelay;};

private:
	mystring	m_strTimestamp;
	mystring	m_strDelay;
};

class BASE_API CSIPWarning:public CSIPHeader
{
public:
	CSIPWarning();
	CSIPWarning(const CSIPWarning &a);
	virtual ~CSIPWarning();
	mystring Encode();
	mystring EncodeNoName();
	int Parse(const char *pbody,int len);
	CSIPWarning& operator=(const CSIPWarning& rhs);
	bool operator==(const CSIPWarning &other) const;
	bool operator!=(const CSIPWarning &other) const;
	void Clear();
	void SetWarnText(const char *pversion){m_strWarnText = pversion;};
	mystring &GetWarnText(){return m_strWarnText;};
	const mystring &GetWarnText()const{return m_strWarnText;};

	void SetWarnAgent(const char *pversion){m_strWarnAgent = pversion;};
	mystring &GetWarnAgent(){return m_strWarnAgent;};
	const mystring &GetWarnAgent()const{return m_strWarnAgent;};

	void SetWarnCode(int code){m_nWarnCode = code;};
	int GetWarnCode(){return m_nWarnCode;};
	int GetWarnCode()const{return m_nWarnCode;};
private:
	int		m_nWarnCode;
	mystring	m_strWarnAgent;
	mystring	m_strWarnText;
};


class BASE_API CSIPCallInfo:public CSIPHeader
{
public:
	CSIPCallInfo();
	CSIPCallInfo(const CSIPCallInfo &a);
	virtual ~CSIPCallInfo();
	mystring Encode();
	mystring EncodeNoName();
	int Parse(const char *pbody,int len);
	CSIPCallInfo& operator=(const CSIPCallInfo& rhs);
	bool operator==(const CSIPCallInfo &other) const;
	bool operator!=(const CSIPCallInfo &other) const;
	void Clear();
	void SetAbsoluteUri(const CSIPAbsoluteUri &auri){m_AbsoluteUri = auri;};
	CSIPAbsoluteUri &GetAbsolute(){return m_AbsoluteUri;};
	const CSIPAbsoluteUri &GetAbsolute()const{return m_AbsoluteUri;};
private:
	CSIPAbsoluteUri	m_AbsoluteUri;
};

class BASE_API CSIPErrorInfo:public CSIPHeader
{
public:
	CSIPErrorInfo();
	CSIPErrorInfo(const CSIPErrorInfo &a);
	virtual ~CSIPErrorInfo();
	mystring Encode();
	mystring EncodeNoName();
	int Parse(const char *pbody,int len);
	CSIPErrorInfo& operator=(const CSIPErrorInfo& rhs);
	bool operator==(const CSIPErrorInfo &other) const;
	bool operator!=(const CSIPErrorInfo &other) const;
	void Clear();
	void SetAbsoluteUri(const CSIPAbsoluteUri &auri){m_AbsoluteUri = auri;};
	CSIPAbsoluteUri &GetAbsolute(){return m_AbsoluteUri;};
	const CSIPAbsoluteUri &GetAbsolute()const{return m_AbsoluteUri;};
private:
	CSIPAbsoluteUri	m_AbsoluteUri;
};

class BASE_API CSIPInReplyTo:public CSIPHeader
{
public:
	CSIPInReplyTo();
	CSIPInReplyTo(const CSIPInReplyTo &a);
	virtual ~CSIPInReplyTo();
	mystring Encode();
	mystring EncodeNoName();
	int Parse(const char *pbody,int len);
	CSIPInReplyTo& operator=(const CSIPInReplyTo& rhs);
	bool operator==(const CSIPInReplyTo &other) const;
	bool operator!=(const CSIPInReplyTo &other) const;
	void Clear();
	void SetCallID(const char *pversion){m_strCallID = pversion;};
	mystring &GetCallID(){return m_strCallID;};
	const mystring &GetCallID()const{return m_strCallID;};
private:
	mystring	m_strCallID;
};

class BASE_API CSIPOrganization:public CSIPHeader
{
public:
	CSIPOrganization();
	CSIPOrganization(const CSIPOrganization &a);
	virtual ~CSIPOrganization();
	mystring Encode();
	mystring EncodeNoName();
	int Parse(const char *pbody,int len);
	CSIPOrganization& operator=(const CSIPOrganization& rhs);
	bool operator==(const CSIPOrganization &other) const;
	bool operator!=(const CSIPOrganization &other) const;
	void Clear();
	void SetOrganization(const char *pversion){m_strOrganization = pversion;};
	mystring &GetOrganization(){return m_strOrganization;};
	const mystring &GetOrganization()const{return m_strOrganization;};
private:
	mystring	m_strOrganization;
};

class BASE_API CSIPPriority:public CSIPHeader
{
public:
	CSIPPriority();
	CSIPPriority(const CSIPPriority &a);
	virtual ~CSIPPriority();
	mystring Encode();
	mystring EncodeNoName();
	int Parse(const char *pbody,int len);
	CSIPPriority& operator=(const CSIPPriority& rhs);
	bool operator==(const CSIPPriority &other) const;
	bool operator!=(const CSIPPriority &other) const;
	void Clear();
	void SetPriority(const char *pversion){m_strPriority = pversion;};
	mystring &GetPriority(){return m_strPriority;};
	const mystring &GetPriority()const{return m_strPriority;};
private:
	mystring	m_strPriority;
};   


class BASE_API CSIPUnsupported:public CSIPHeader
{
public:
	CSIPUnsupported();
	CSIPUnsupported(const CSIPUnsupported &e);
	virtual ~CSIPUnsupported();
	int Parse(const char *pbody,int len);
	mystring Encode();
	mystring EncodeNoName();
	mystring &GetOptionTag(){return m_strOptionTag;};
	const mystring &GetOptionTag()const{return m_strOptionTag;};
	void SetOptionTag(const char *ptag){m_strOptionTag = ptag;};
	CSIPUnsupported& operator=(const CSIPUnsupported& rhs);
	bool operator==(const CSIPUnsupported& other) const;
	bool operator!=(const CSIPUnsupported& other) const;
	void Clear();
private:
	mystring m_strOptionTag;
};

class BASE_API CSIPScale: public CSIPHeader
{
public:
	mystring Encode();
	mystring EncodeNoName();

	CSIPScale(float ex){m_fScale=ex;m_eType = Scale;};
	CSIPScale(const CSIPScale &ex){*this = ex;};
	virtual ~CSIPScale(){};
	void SetScale(float s){m_fScale = s;};
	float GetScale()const {return m_fScale;};	
	CSIPScale& operator=(const CSIPScale& rhs);
	bool operator==(const CSIPScale& other) const;
	bool operator!=(const CSIPScale& other) const;
	bool operator<(const CSIPScale& other) const;
	int Parse(const char *pbody,int len);
protected:
	float	m_fScale;
};


class BASE_API CSIPSeek: public CSIPHeader
{
public:
	mystring Encode();
	mystring EncodeNoName();
	CSIPSeek(float ex){m_nPos=ex;m_eType = Seek;};
	CSIPSeek(const CSIPSeek &ex){*this = ex;};
	virtual ~CSIPSeek(){};
	void SetPos(float s){m_nPos = s;};
	float GetPos()const {return m_nPos;};	
	CSIPSeek& operator=(const CSIPSeek& rhs);
	bool operator==(const CSIPSeek& other) const;
	bool operator!=(const CSIPSeek& other) const;
	bool operator<(const CSIPSeek& other) const;
	int Parse(const char *pbody,int len);
protected:
	float m_nPos;
};
//#endif
#endif // !defined(AFX_HEADER_H__316AE8D6_500A_4FE9_8398_4B2924A0B168__INCLUDED_)
